from django.conf.urls import url
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.routers import DefaultRouter

from .views import statistical, users, skus, specs, sku_image

urlpatterns = [
    # 登录请求路由
    url('^authorizations/$', obtain_jwt_token),
    # 统计总用户量路由
    url('^statistical/total_count/$', statistical.UserCountView.as_view()),
    # 统计日活用户路由
    url('^statistical/day_active/$', statistical.UserDayActiveCountView.as_view()),
    # 统计月增用户路由
    url('^statistical/month_increment/$', statistical.UserMonthIncrementView.as_view()),
    # 统计分类商品的每天访问量路由
    url('^statistical/goods_day_views/$', statistical.GoodsDayView.as_view()),

    # 获取用户路由
    url('^users/$', users.UserView.as_view()),

    # 新增SPU规格相关路由
    url('^goods/simple/$', specs.SpecsView.as_view({'get': 'simple'})),

    # 新增SKU图片相关路路由
    url('^skus/simple/$', sku_image.SKUImageView.as_view({'get': 'simple'})),

    # 新增SKU获取商品分类路由
    url('^skus/categories/$', skus.SKUView.as_view({'get': 'category'})),

    # 获取SPU规格选项路由
    url('^goods/(?P<pk>\d+)/specs/$', skus.SKUView.as_view({'get': 'specs'}))

]

"""
如果用视图集定义的路由，定义正确，但是访问时发生404的错误时，调整下每个模块的路由顺序就可以访问了
"""
# 图片路由
router = DefaultRouter()
router.register('skus/images', viewset=sku_image.SKUImageView, base_name='sku_images')
print(router.urls)
urlpatterns += router.urls

# sku信息路由
router = DefaultRouter()
router.register('skus', viewset=skus.SKUView, base_name='skus')
print(router.urls)
urlpatterns += router.urls

# SPU规格管理路由
router = DefaultRouter()
router.register('goods/specs', viewset=specs.SpecsView, base_name='specs')
print(router.urls)
urlpatterns += router.urls
